//
//  RefreshMeituanView.swift
//  VVbo
//
//  Created by Mr.Run on 2017/9/5.
//  Copyright © 2017年 Mr.Run. All rights reserved.
//

import UIKit

class RefreshMeituanView: RefreshView {
    @IBOutlet weak var buildingIconView: UIImageView!
    
    @IBOutlet weak var earthIconView: UIImageView!
    
    @IBOutlet weak var kangrooIconView: UIImageView!
    
    override var parentViewHeight: CGFloat {
        didSet{
            //print(parentViewHeight)
            if parentViewHeight < 42 {
                return
            }
            var scale: CGFloat
            if parentViewHeight > 126 {
                scale = 1
            }else{
                scale = 1 - ((126 - parentViewHeight) / (126 - 42))
            }
            kangrooIconView.transform = CGAffineTransform(scaleX: scale, y: scale)
        }
        
    }
    
    override func awakeFromNib() {
        superview?.awakeFromNib()
        
        let bImgae1 = #imageLiteral(resourceName: "icon_building_loading_1")
        let bImgae2 = #imageLiteral(resourceName: "icon_building_loading_2")
        
        buildingIconView.image = UIImage.animatedImage(with: [bImgae1, bImgae2], duration: 0.5)
        
        let kImgae1 = #imageLiteral(resourceName: "icon_small_kangaroo_loading_1")
        let kImgae2 = #imageLiteral(resourceName: "icon_small_kangaroo_loading_2")
        
        kangrooIconView.image = UIImage.animatedImage(with: [kImgae1, kImgae2], duration: 0.3)
        
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.toValue = -Double.pi * 2
        anim.repeatCount = MAXFLOAT
        anim.duration = 3
        anim.isRemovedOnCompletion = false
        earthIconView.layer.add(anim, forKey: nil)
        
//        kangrooIconView.transform = CGAffineTransform(scaleX: 0.2, y: 0.2)
        let x = self.bounds.width * 0.5
        let y = self.bounds.height - 42
        kangrooIconView.center = CGPoint(x: x, y: y)
        kangrooIconView.layer.anchorPoint = CGPoint(x: 0.5, y: 1)
        
    }
    
}
